package Test.stream流测试;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @Author kirito
 * @Date 2023/12/13 19:01
 * @PackageName:Test.stream流测试
 * @ClassName: a
 * @Description:
 * @Version 1.0
 */
public class StreamDemo10 {
    public static void main(String[] args) {
        List<Person> list = new ArrayList<>();
        list.add(new Person("马化腾",25,3000));
        list.add(new Person("李彦宏",27,2545));
        list.add(new Person("雷军",35,4515));
        list.add(new Person("马云",55,9877));
        // 把年龄大于30岁的人，转成一个list集合
        List<Person> collect = list.stream().filter(person -> person.getAge() > 30).collect(Collectors.toList());
        // 遍历输出（输出雷军和马云）
        for (Person person : collect) {
            System.out.println(person);
        }

        System.out.println("----------");

        List<Person> list2 = new ArrayList<>();
        list2.add(new Person("马化腾",25,3000));
        list2.add(new Person("李彦宏",27,2545));
        list2.add(new Person("雷军",35,4515));
        list2.add(new Person("马云",55,9877));
        // 把姓马的人，转成Set集合
        Set<Person> set = list2.stream().filter(person -> person.getName().startsWith("马")).collect(Collectors.toSet());
        // 输出马云和马化腾
        set.forEach(System.out::println);





    }
}


